<script setup lang="ts">
import { ref } from 'vue'
import { PEFile } from "@/utils/pe/PEFile.ts";
import pe from "@/utils/pe";

defineProps<{ msg: string }>()

const count = ref(0)
const imgUrl = ref()
const handleInput = async (event: any) => {
  const file = event.target.files[0]
  const peFile = new PEFile(file)
  await peFile.read()
  const icons = await peFile.getIcons()
// 文件类型转base64
  const fileToBase64 = (file: File, callback: any) => {
    const reader = new FileReader();
    reader.onload = function (evt) {
      if (typeof callback === 'function') {
        callback(evt.target!.result)
      } else {
        console.log("我是base64:", evt.target!.result);
      }
    };
    reader.readAsDataURL(file);
  };
  
  if(icons.length > 0){
    const data = new File([await icons[icons.length-1].getData()], 'data.png', {type: 'image/png'})
    fileToBase64(data, (base64: any) => {
      imgUrl.value = base64
      console.log("我是base64:", base64);
    });
  }
}
</script>

<template>
    <h1>{{ msg }}</h1>

    <div class="card">
        <input type="file" @input="handleInput">
        <button type="button" @click="count++">count is {{ count }}</button>
        <p>
            Edit
            <code>components/HelloWorld.vue</code> to test HMR
        </p>
    </div>

    <p>
        Check out
        <a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
        >create-vue</a
        >, the official Vue + Vite starter
    </p>
    <p>
        Learn more about IDE Support for Vue in the
        <a
                href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support"
                target="_blank"
        >Vue Docs Scaling up Guide</a
        >.
    </p>
    <img style="height: 500px;width: 500px" v-if="imgUrl" :src="imgUrl" alt="file logo">
    <p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
</template>

<style scoped>
.read-the-docs {
    color: #888;
}
</style>
